<?php

/**
 * Created by PhpStorm.
 * User: IsSwm
 * Date: 2017/6/20
 * Time: 15:38
 */

namespace app\home\controller;

use think\Controller;

class Home extends Controller
{
    //首页轮播图片
    public function banner()
    {
        $banner = db('banner')->select(function ($query) {
            $query->where('position', 0)
                ->order('id desc')
                ->limit(3);
        });
        if ($banner) {
            foreach ($banner as $k => $value) {
//                时间戳转换
                $banner[$k]['add_time'] = date('y-m-d', $value['add_time']);
            }
        }
        return $this->sucReturn($banner);

    }

//$map['status'] = 0;
//$lists = db('article')->select(function ($query) use ($offset, $pageSize) {
//            $query->where('status', 0)
//                ->order('id desc')
//                ->limit($offset, $pageSize);
//        });
//return $this->sucReturn($lists);

    //首页
    public function types()
    {

        //首页内容
        $types = array();

        for ($i = 0; $i <= 6; $i++) {
            $type_id = $i;

            if ($type_id) {
                //轮播图
                $map_loop['position'] = $type_id;
                $banner = db('banner')->field('pic')->where($map_loop)->order('id', 'desc')->limit(2)->select();
                //内容
//                $sql = "SELECT type_id,title,writer,pic,content FROM w_first WHERE type_id='$type_id' ORDER BY id";
                $map_content['type_id'] = $type_id;
                $lists = db('first')->field('type_id,title,writer,pic,content,add_time')->where($map_content)->order('id')->find();
                if ($lists) {
                    $lists['add_time'] = date('y-m-d', $lists['add_time']);
                    $lists['banner'] = $banner;
                }
                $types[] = $lists;
            }
        }

        //企业动态
//        $sql = "SELECT * FROM w_qiye WHERE status='0' ORDER BY id DESC LIMIT 3";
        $qi_ye = db('qiye')->where('status', '0')->order('id')->limit(3)->select();

        if ($qi_ye) {
            foreach ($qi_ye as $k => $value) {
                $qi_ye[$k]['add_time '] = date('y-m-d', $value['add_time']);
            }
        }

        $my_array = array('types' => $types, 'qiye' => $qi_ye);
        return $this->sucReturn($my_array);


    }
}
        //商品
